/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Extended Service Controller Custom Collection Class
 *		A custom collection class for storing <see cref="ServiceControllerEx"/> objects.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.Collections;
using System.ServiceProcess;
using Microsoft.Win32;
using System.Threading;

namespace Adaptive.Foundation.SysTools
{
    /// <summary>
    /// A custom collection class for storing <see cref="ServiceControllerEx"/> objects.
    /// </summary>
    public class ServiceControllerExCollection : GenericCollectionBase<ServiceControllerEx>
    {
        /*------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *----------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public ServiceControllerExCollection()
            : base()
        {
        }
        #endregion

        /*------------------------------------------------------------------------
         * Protected Methods
         *----------------------------------------------------------------------*/
        #region Protected Methods
        /// <summary>
        /// Gets the unique reference key for the object being appended to
        /// the collection instance.
        /// </summary>
        /// <param name="itemToGetKeyFor">
        /// The object being appended to the collection.
        /// </param>
        /// <returns>
        /// The unique key used to reference the instance.
        /// </returns>
        protected override string GetKeyForObject(ServiceControllerEx itemToGetKeyFor)
        {
            if (itemToGetKeyFor == null)
                return string.Empty;
            else
                return itemToGetKeyFor.ServiceName;
        }
        #endregion

        /*------------------------------------------------------------------------
         * Public Methods
         *----------------------------------------------------------------------*/
        #region Public Methods
        /// <summary>
        /// Returns the contents of the collection in an array container.
        /// </summary>
        /// <returns>
        /// A <see cref="ServiceControllerEx"/> array.
        /// </returns>
        public ServiceControllerEx[] ToArray()
        {
            ServiceControllerEx[] returnValue = null;
            int count = 0;
            int length = Count;

            returnValue = new ServiceControllerEx[length];
            for (count = 0; count < length; count++)
                returnValue[count] = this[count];

            return returnValue;
        }
        #endregion
    }
}
